package org.base.core.utils;

import java.text.SimpleDateFormat;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
	
	public static final String DATA_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	public static String toJsonString(Object object,String dataFormate) {
		try {
			ObjectMapper mapper = getObjectMapper();
			SimpleDateFormat sdf = new SimpleDateFormat(dataFormate);
			return mapper.writer(sdf).writeValueAsString(object);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public static String toJsonString(Object object) {
		return toJsonString(object, DATA_FORMAT);
	}
	
	private static ObjectMapper getObjectMapper() {
		ObjectMapper mapper = new ObjectMapper();
		return mapper;
	}

}
